package com.zhou.common;

import com.zhou.test.entity.SystemUser;
import org.springframework.stereotype.Component;

/**
 * @Author: zhoujinchuan
 * @Description: TODO（请添加描述）
 * @CreateTime: 2023/10/26 9:33
 */
@Component
public class UserContext {
    private static ThreadLocal<SystemUser> userThreadLocal = new ThreadLocal<>();

    public static void setUser(SystemUser user) {
        userThreadLocal.set(user);
    }

    public static SystemUser getUser() {
        return userThreadLocal.get();
    }

    public static Integer getUserId(){
        return userThreadLocal.get().getId();
    }

    public static void clear() {
        userThreadLocal.remove();
    }
}
